<template>
  <div class="bottom-bar" align="right">
    <my-button ref="act-button" type="primary"
               v-if="this.$props.currOrder.status.id===0
                      && (!this.$props.currOrder.orderGroupId || (this.$props.currOrder.orderGroupId>0 && (this.$props.currOrder.orderGroupStatus.id===2 || this.$props.currOrder.orderGroupStatus.id===6)))
                     && (!this.$props.currOrder.sendStatus|| this.$props.currOrder.sendStatus.id===0)
                     && this.$props.currOrder.sendType.id===0
                     && (this.$props.currOrder.payType && this.$props.currOrder.payType.id>-1)"
      :click="function(){startSend()}" text="确认发货" access-action="Order/manage"></my-button>

    <my-button ref="act-button" type="primary"
               v-if="this.$props.currOrder.status.id===0 && this.$props.currOrder.sendStatus.id===0 && this.$props.currOrder.sendType.id===1 && (this.$props.currOrder.payType && this.$props.currOrder.payType.id>-1)"
               :click="function(){startSend()}" text="店铺开始配送" access-action="Order/manage"></my-button>

    <my-button ref="act-button" type="primary"
               v-if="this.$props.currOrder.status.id===1 && this.$props.currOrder.sendStatus.id===1 && this.$props.currOrder.sendType.id===1 && (this.$props.currOrder.payType && this.$props.currOrder.payType.id>-1)"
               :click="function(){sendToMember()}" text="确认送达" access-action="Order/manage"></my-button>

    <my-button ref="act-button" type="primary"
               v-if="this.$props.currOrder.status.id===0 && this.$props.currOrder.sendType.id===2 && (this.$props.currOrder.payType && this.$props.currOrder.payType.id>-1)"
               :click="function(){confirmTake()}" text="确认自提" access-action="Order/manage"></my-button>
  </div>
</template>

<script>
import MyButton from './MyButton'
export default {
  name: 'OrderActButton',
  components: {MyButton},
  data:function () {
    return {
      isShow:true
    }
  },
  props:{
    currOrder:Object,
    callBack:Function
  },
  mounted () {
    let $this=this
    setTimeout(function () {
      if (!$this.$refs['act-button']){
        $this.isShow=false
      }else{
        $this.isShow=true
      }
    },500)
  },
  methods:{
    // 售后(退换货)
    apply:function () {
      var query={
        orderId:this.$props.currOrder.id,
        applyId:this.$props.currOrder.applyId
      }
      this.$router.push({
        name:'OrderApply',
        query:query
      })
    },
    // 确认自提
    confirmTake:function () {
      let $this=this
      $this.$prompt('请输入 提货码', '系统提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /^\d{5}$/,
        inputErrorMessage: '提货码 格式不正确'
      }).then(({ value }) => {
        $this.MyRequest(this.ApiDoNameShop+'Order/completeTake',{id:this.$props.currOrder.id,takeNumber:value},function (data) {
          $this.$message.success('操作成功')
          if (typeof $this.$props.callBack==='function'){
            $this.$props.callBack()
          }
        })
      }).catch(() => {
      });

    },
    sendToMember: function () {
      let $this = this
      $this.$confirm('您确认要进行该操作吗(确认送达至用户)?', '系统提醒', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        $this.MyRequest(this.ApiDoNameShop + 'Order/sendToMember', {
          id:this.$props.currOrder.id
        }, function (data) {
          $this.$message.success('操作成功')
          if (typeof $this.$props.callBack==='function'){
            $this.$props.callBack()
          }
        })
      })
    },
    // 开始配送
    startSend: function () {
      let $this=this
      if (this.$props.currOrder.sendType.id===1){
        $this.$confirm('您是否取要进行该操作?', '系统提示', {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          $this.MyRequest(this.ApiDoNameShop+'Order/sendSameCity',{
            id:this.$props.currOrder.id,
            goodsWeight: 1,
            goodsCount: 1,
          },function () {
            $this.$message.success('操作成功')
            if (typeof $this.$props.callBack==='function'){
              $this.$props.callBack()
            }
          })
        }).catch(() => {

        })
      }else{
        this.bus.$emit('OrderStartSendDialogCallBus',this.$props.currOrder,function () {
          if (typeof $this.$props.callBack==='function'){
            $this.$props.callBack()
          }
        })
      }

    },
  }
}
</script>

<style scoped>

</style>
